﻿using BW.EatRabbit.API.Application.Commands.DeeprocessingCompany;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.DeeprocessingCompany
{
    public class DeepCompanyCreateCommandHandler : IRequestHandler<DeepCompanyCreateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<DeepProcessing_Company> _companyRepository;
        public DeepCompanyCreateCommandHandler(IBaseRepository<DeepProcessing_Company> companyRepository)
        {
            _companyRepository = companyRepository;
        }
        public Task<APIResult<int>> Handle(DeepCompanyCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            DeepProcessing_Company company = new DeepProcessing_Company();
            company.CompanyName = request.CompanyName;
            company.LicenseNum = request.LicenseNum;
            company.ProductionBatch = request.ProductionBatch;
            company.Creator = request.UserNickname;
            _companyRepository.AddEntity(company);

            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            return Task.FromResult(result);
        }
    }
}
